package com.xbongbong.paas.pojo;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.saas.enums.MobileDetailThroughTypeEnum;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;
import java.util.List;

/**
 * @author: wufeng
 * @date: 2018/8/28 10:39
 * @desrcption: 摘要数据对象
 */
@Getter
@Setter
@ToString
public class SummaryDataPoJo implements Serializable {

    private static final long serialVersionUID = 2940950185888967422L;

    private Long id;

    /**
     * 字段唯一键，前端生成
     */
    private String attr;

    /**
     * SaaS字段标志
     */
    private String saasAttr;

    /**
     * 字段名称
     */
    private String attrName;

    /**
     * 数据
     */
    private List<Object> value;

    /**
     * 字段类型
     */
    private Integer fieldType;

    /**
     * 标记这个字段在再要中显示时是否有特殊之处
     * "normal" 正常显示
     * "phone" 电话号码，点击电话号码可以拨打
     * "address" 地址，点击地址可以跳转地图
     * "direct" 关联业务，点击可以跳转到关联业务
     * {@link com.xbongbong.saas.enums.MobileDetailThroughTypeEnum}
     */
    private String type;

    /**
     * 跟type字段对应
     * type为"normal"时不需要额外信息
     * type为"address"时放入经纬度{"latitude": 256, "longitude": 356}
     * type为"direct"时放入关联业务id和类型{"dataId": 100, "businessType": 104
     * }
     */
    private JSONObject extra;
    /**
     * 跳转过后的title
     */
    private String title;
    /**
     * 摘要状态
     */
    private String status;

    /**
     * 摘要颜色
     */
    private String color;

    public void setDirectExtra(Long dataId, Integer businessType) {
        JSONObject extraObj = new JSONObject();
        extraObj.put("dataId", dataId);
        extraObj.put("businessType", businessType);
        this.extra = extraObj;
        this.type = MobileDetailThroughTypeEnum.DIRECT.getType();
    }

    public void setAddressExtra(Double latitude, Double longitude) {
        JSONObject extraObj = new JSONObject();
        extraObj.put("latitude", latitude);
        extraObj.put("longitude", longitude);
        this.extra = extraObj;
        this.type = MobileDetailThroughTypeEnum.ADDRESS.getType();
    }

    public void setAddressExtra(Double latitude, Double longitude, String title) {
        JSONObject extraObj = new JSONObject();
        extraObj.put("latitude", latitude);
        extraObj.put("longitude", longitude);
        extraObj.put("title", title);
        this.extra = extraObj;
        this.type = MobileDetailThroughTypeEnum.ADDRESS.getType();
    }

    public void setPhoneExtra() {
        this.type = MobileDetailThroughTypeEnum.PHONE.getType();
    }

    public void setImageExtra() {
        this.type = MobileDetailThroughTypeEnum.IMAGE.getType();
    }

    public SummaryDataPoJo() {
    }

    public SummaryDataPoJo(String attr, String attrName, Integer fieldType) {
        this.attr = attr;
        this.attrName = attrName;
        this.fieldType = fieldType;
    }

    public SummaryDataPoJo(String attr, String attrName, Integer fieldType, List<Object> value) {
        this.attr = attr;
        this.attrName = attrName;
        this.fieldType = fieldType;
        this.value = value;
    }

    public void setMemo() {
        this.type = MobileDetailThroughTypeEnum.MEMO.getType();
    }

    public SummaryDataPoJo(String attr, String attrName,Integer fieldType, List<Object> value,JSONObject summaryExtraDataPoJo) {
        this.attr = attr;
        this.attrName = attrName;
        this.fieldType = fieldType;
        this.value = value;
        this.type = "direct";
        this.extra = summaryExtraDataPoJo;
    }
}
